<template>
	<view class="apps">
		<uv-loading-page :loading="pageLoading" loading-text="正在加载..." font-size="14px" loading-mode="spinner"></uv-loading-page>
		<view style="padding:5px 0px 5px 5px; border-bottom: 1px solid #e1e1e1;" v-for="(item,index) in list">
			<uv-list-item :title="item.title" link :to="'/pages/detail/detail?id='+item.id"></uv-list-item>
		</view>
	</view>
</template>

<script>
	let app;
	import * as ww from '@wecom/jssdk'
	export default {
		data() {
			return {
				pageLoading:true,
				pageMore:true,
				page:1,
				pageSize:20,
				list:[]
			}
		},
		onLoad(opt) {
			if(!!opt.token){
				uni.setStorageSync('WeApp_token',opt.token);
			}
			app = this;
			ww.register({
				corpId: 'ww5d7b19c3c1ce8e1f',    // 必填，当前用户企业所属企业ID
				jsApiList: ['hideAllNonBaseMenuItem','hideOptionMenu','createWWLoginPanel'],  
				agentId:'1000007',
				getConfigSignature: async function(){
				  const configData = await app.request({
						url: '/auth',
						data:{'agent_id':''}
					})
					//app.alert(JSON.stringify(configData));
					return configData.data;
				},                
				getAgentConfigSignature: async function(){
					const AgentConf = await app.request({
						url: '/auth',
						data:{'agent_id':'1000007'}
					})
					//app.alert(JSON.stringify(AgentConf));
					return AgentConf.data;
				}
			})
			ww.hideAllNonBaseMenuItem();
			ww.hideOptionMenu();
			app.getlist();
		},
		onReachBottom() {
			if(app.pageMore){
				app.getlist();
			}
		},
		methods: {
			handle(){
				uni.navigateTo({
					url:'/pages/detail/detail'
				})
			},
			getlist(){
				let page = app.page;
				let page_size = app.pageSize;
				app.pageLoading =true;
				app.request({
					url:"/index",
					data:{page:page,page_size:page_size},
					success:function(res){
						if(res.data.length < app.pageSize){
							app.pageMore = false;
						}
						if(res.code == 1){
							if(page == 1){
								app.list = res.data;
								
								if(res.data.length == 0){
									app.pageMore=false;
								}
							}else{
								app.list.push(...res.data);
							}
						}
						app.pageLoading = false;
					}
				})
			}
			
		}
	}
</script>

<style scoped>
	.uv-icon{font-size: 20px !important;}
	.uv-list-item__content-title{font-size: 16px !important;}
</style>
